﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Cosmetic.Logic;

namespace WebApp.Controls
{
    public partial class TimeLimitProduct : System.Web.UI.UserControl
    {
        PlateManager PM = new PlateManager();

        protected void Page_Load(object sender, EventArgs e)
        {
            Bind();
        }

        private void Bind()
        {
            this.ListView1.DataSource = PM.GetTimeLimitSales();
            this.ListView1.DataBind();
        }


        protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e)
        {
            //Label hour = e.Item.FindControl("lbHour") as Label;
            //Label minute = e.Item.FindControl("lbMinute") as Label;
            //Label second = e.Item.FindControl("lbSecond") as Label;

            //HiddenField hf = e.Item.FindControl("HiddenField1") as HiddenField;
            //DateTime DTEnd = Convert.ToDateTime(hf.Value);
            //TimeSpan duration = (DateTime.Now - DTEnd);
            //hour.Text = duration.Hours.ToString()=="0"? "0":duration.Hours.ToString().Remove(0, 1);
            //minute.Text = duration.Minutes.ToString() == "0" ? "0" : duration.Minutes.ToString().Remove(0, 1);
            //second.Text = duration.Seconds.ToString() == "0" ? "0" : duration.Seconds.ToString().Remove(0, 1);
            HiddenField hf = e.Item.FindControl("HiddenField1") as HiddenField;
            HtmlInputHidden HtmlDuration = e.Item.FindControl("Duration") as HtmlInputHidden;
            DateTime DTEnd = Convert.ToDateTime(hf.Value);
            TimeSpan duration = DTEnd - DateTime.Now ;
            HtmlDuration.Value =  Convert.ToInt32(duration.TotalSeconds).ToString();

            if (duration.TotalSeconds <= 0)
            {
                Panel pl = e.Item.FindControl("Panel1") as Panel;
                pl.Controls.Clear();
                Literal lt = new Literal();
                lt.Text = "<span class=\"newtxt_red2\">"+"抢购结束"+"</span>";
                pl.Controls.Add(lt);
            }
        } 
    }
}